package com.ziq.baselib.test.page

import android.os.Bundle
import android.view.ViewGroup
import android.widget.TextView
import com.facebook.drawee.view.SimpleDraweeView
import com.facebook.imagepipeline.request.ImageRequest
import com.ziq.base.base.BaseActivity
import com.ziq.base.extension.binding
import com.ziq.base.utils.ImageUtil
import com.ziq.base.view.AutoRollViewPager
import com.ziq.baselib.R
import com.ziq.baselib.databinding.ActivityAutoRollViewPagerBinding

class AutoRollViewPagerActivity: BaseActivity() {

    private val binding : ActivityAutoRollViewPagerBinding by binding()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.autoRollViewPager.adapter = mRollViewPagerAdapter;
        val dataList: ArrayList<PhotoModel> = ArrayList()
        dataList.add(PhotoModel("https://qa-media-api.xogrp.com/images/986509f2-0a88-4480-ab41-4e7ec7ceb243.webp", "1-photo"))
        dataList.add(PhotoModel("https://qa-media-api.xogrp.com/images/5e917e94-d6da-422d-be39-2667f143b598.webp", "2-photo"))
        dataList.add(PhotoModel("https://qa-media-api.xogrp.com/images/58fe2f3a-0ecc-4b50-91ab-f378214f49f4.webp", "3-photo"))
        dataList.add(PhotoModel("https://qa-media-api.xogrp.com/images/088ea6d6-74fd-49a1-a483-0f34e847714c.webp", "4-photo"))
        dataList.add(PhotoModel("https://qa-media-api.xogrp.com/images/81036808-509e-4254-aa2a-e531791b436e.webp", "5-photo"))
        mRollViewPagerAdapter.data = dataList
    }


    private val mRollViewPagerAdapter: AutoRollViewPager.RollViewPagerAdapter<PhotoModel> = object : AutoRollViewPager.RollViewPagerAdapter<PhotoModel>(){
        override fun getItemLayoutRes(): Int {
            return R.layout.auto_roll_view_pager_item
        }

        override fun onBindItemView(rootView: ViewGroup?, position: Int, realPosition: Int) {
            val model = getItem(realPosition)
            val imageView = rootView?.findViewById(R.id.img) as SimpleDraweeView
            ImageUtil.updateImageFromNetwork(imageView, model.url, ImageRequest.CacheChoice.DEFAULT)
            val textView = rootView.findViewById(R.id.text) as TextView
            textView.text = model.text
        }

    }

    internal inner class PhotoModel(var url: String, var text: String)
}